import Vue 			from 'vue'
import util 		from '../../util'
import axios 		from 'axios'
import { Toast,Dialog } 	from 'vant';
Vue.use(Toast,Dialog);

export default {
	name: 'mySetting',
	data(){
		return {
			nickName:'',
			headImg:'',
			mobile:'',
			realNameStatus:4,		//0:未认证  1:审核中  2:审核通过   3:审核驳回  4:显示为空
		}
	},
	methods:{
		clicRight(){
			if(this.wait){
				let dialogDebug = window.localStorage.getItem('dialogDebug');
				if(dialogDebug && dialogDebug==='1'){
					//清除悬浮窗
					window.localStorage.removeItem('dialogDebug')
				}else{
					//设定悬浮窗
					window.localStorage.setItem('dialogDebug','1')
				}
			}
		},
		clickLeft(){
			this.wait = true;
			setTimeout(()=>{
				this.wait = false;
			},1000)
		},
		jump(num){
			if(num == 1){
				//设置头像
				util.callHandler('updateUserAvatar',{},res => {
					console.log(res)
				})
			}else if(num == 2){
				//设置昵称
				this.$router.push('/editNickName')
			}
		},
		isRealName(){
			if(this.version >= 412 || this.realNameStatus == 0){
				util.callHandler('openUrl',{
					url: 'flutterApp://pushPage?routeName=kycMainPage',
					title:'',
					needLogin:false,
					popVC:false,		//跳转的时候是否干掉当前页面
	                hiddenNav:false,	//是否全屏
				},res => {
					console.log(res)
				})
			}else{
				//其他状态，直接跳转到认证结果状态
				this.$router.push({
					path:'/realNameStatus',
					query:{
						hideBtn:1
					}
				})
			}
		},
		// loginOut(){
		// 	Dialog.confirm({
  //               title: '提醒',
  //               message: '确定退出登录？',
  //               className:'sellType-dialog',
  //               cancelButtonColor:'#1989fa',
  //               confirmButtonText:'确定',
  //               cancelButtonText:'取消',
  //               overlayClass:'sellType-mark'
  //           }).then(() => {
  //           	//加退出清除，防止万一安卓无法清除
  //           	// window.localStorage.removeItem('token');
  //               // util.delCookie('localToken');
  //           	util.callHandler('settingLogout',{},res => {
  //           		// localStorage.removeItem('token');
  //                   // util.delCookie('localToken');
		// 		})
  //               console.log('confirm')
  //           }).catch(() => {
  //               console.log('cancel')
  //           })
  //       },
		init(){
			if(this.version >= 412){

			}else{
				util.fetch(`${util.ajaxUrl}/otc/otc-config`,{}).then(res => {
					if(res.retCode === 0){
						this.realNameStatus = res.retData.kyc_status;
						util.setStorage('realNameStatus',this.realNameStatus)
					}else{
						Toast(res.retMsg || this.$t('noError'))
					}
				}).catch(error => {
					console.log(error)
				})
			}
			
			//获取用户信息
			util.callHandler('getUserInfo',{},res => {
				// alert(JSON.stringify(res))
				this.nickName = res.nickname;
				this.headImg = res.head_img;
				this.mobile = res.mobile;
			})
		},
		goBack(){
			util.navigateBack(-1,this)
		}
	},
	created() {
		if(util.getStorage('realNameStatus')) this.realNameStatus = util.getStorage('realNameStatus');
		util.waitSDKReady().then(token => {
			this.token = token;
			this.init();
		}).catch((e) => {
			Toast(this.$t('getTokenFail'))
		})
		setTimeout(() => {
			//退出登录的时候native调用H5方法清除token缓存
			util.registerHandler('loginOutDeleteToken',res => {
				window.token = '';
				this.token = '';
				localStorage.removeItem('token');
			})
			util.registerHandler('refreshCommonRequestWhenGoBackView',res => {
				if(this.token) this.init();
				util.callHandler('setStatusBarStyle',{
					style:'dark'
				})
			})
			util.callHandler('setStatusBarStyle',{
				style:'dark'
			})
		},300)
    }
}